﻿using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[Serializable]
internal class EditorTimelineObjectMap
{
    private static Dictionary<USTimelineBase, USTimelineBaseEditor> data;

    public static void Clean()
    {
        if (data != null)
        {
            foreach (KeyValuePair<USTimelineBase, USTimelineBaseEditor> pair in data)
            {
                UnityEngine.Object.DestroyImmediate(pair.Value);
            }
            data.Clear();
        }
    }

    public static USTimelineBaseEditor GetKey(USTimelineBase timelineBase)
    {
        if (Data.ContainsKey(timelineBase) && (Data[timelineBase] == null))
        {
            Data.Remove(timelineBase);
        }
        if (!Data.ContainsKey(timelineBase))
        {
            System.Type aBaseClass = typeof(USTimelineBaseEditor);
            System.Type type = aBaseClass;
            foreach (System.Type type3 in USEditorUtility.GetAllSubTypes(aBaseClass))
            {
                if (type3.IsSubclassOf(aBaseClass))
                {
                    foreach (Attribute attribute in type3.GetCustomAttributes(true))
                    {
                        CustomEditor editor = attribute as CustomEditor;
                        if (editor.m_InspectedType == timelineBase.GetType())
                        {
                            type = type3;
                        }
                    }
                }
            }
            USTimelineBaseEditor editor2 = ScriptableObject.CreateInstance(type) as USTimelineBaseEditor;
            Data.Add(timelineBase, editor2);
            editor2.TargetTimeline = timelineBase;
        }
        return Data[timelineBase];
    }

    public static Dictionary<USTimelineBase, USTimelineBaseEditor> Data
    {
        get
        {
            if (data == null)
            {
                data = new Dictionary<USTimelineBase, USTimelineBaseEditor>();
            }
            return data;
        }
    }
}

